package com.liaoban.app.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.liaoban.app.R;
import com.liaoban.app.api.type.AnchorAgreement;

import java.util.List;

/**
 * 主播协议
 */
public class AnchorAgreementAdapter extends BaseQuickAdapter<AnchorAgreement, BaseViewHolder> {

    public AnchorAgreementAdapter(@Nullable List<AnchorAgreement> data) {
        super(R.layout.item_anchor_agreement, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, AnchorAgreement item) {
        if (helper.getLayoutPosition() == 0) {
            helper.setVisible(R.id.iv_zongze, true);
            helper.setVisible(R.id.tv_pos, false);
        } else {
            helper.setVisible(R.id.iv_zongze, false);
            helper.setVisible(R.id.tv_pos, true);
            helper.setText(R.id.tv_pos, "" + helper.getLayoutPosition());
        }
        helper.setText(R.id.tv_title, item.getTitle());
        helper.setText(R.id.tv_content, item.getContent());
        TextView tvContent = helper.getView(R.id.tv_content);
        ImageView ivMore = helper.getView(R.id.iv_more);
        helper.getView(R.id.layout_title).setOnClickListener(view -> {
            if (View.VISIBLE == tvContent.getVisibility()) {
                tvContent.setVisibility(View.GONE);
                ivMore.setSelected(false);
            } else {
                tvContent.setVisibility(View.VISIBLE);
                ivMore.setSelected(true);
            }
        });
    }
}
